import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-10-29
 * Time: 16:56
 */
public class Demo3 {
    public static int sum1 = 0;
    public static int sum2 = 0;
    public static void main(String[] args) throws InterruptedException {
        //开始时间
        long start = System.currentTimeMillis();
        Random random = new Random();
        int[] arr = new int[10000000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(100) + 1;
        }
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < arr.length; i += 2) {
                sum1 += arr[i];
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 1; i < arr.length; i += 2) {
                sum2 += arr[i];
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        //结束时间
        long end = System.currentTimeMillis();
        System.out.println(sum1);
        System.out.println(sum2);
        System.out.println(sum1 + sum2);
        System.out.println(end-start);
    }
}
